feat: add user-specified mounts to container machines - #1837
feat: add user-specified mounts to container machines#1837danielsyauqi wants to merge 3 commits into
Conversation
|
@danielsyauqi can you describe how to test these changes locally? You didn't check the
I have also tried it with running a local |
|
This feature is great and exactly what I wanted. I hope it continues to be developed to meet the requirements for merging pull requests. |
Add a repeatable --mount host:guest[:ro|rw] option to container machine create. Persist validated mounts in the machine boot configuration, expose them through inspect, and add them as virtiofs shares at boot. Include backward-compatible decoding, documentation, and unit coverage.
Remove the unused generic return value so the helper compiles cleanly when warnings are treated as errors.
cee5710 to
eb6be3b
Compare
|
@mareksapota Thanks for testing this, and sorry for the slow follow-up. The important detail is that machine operations go through the launchd-managed I rebased the branch and retested it with the CLI and every service plugin built from the same revision. Here is the matched-stack procedure I used: make container
bin/container system stop
TEST_ROOT="$(mktemp -d)"
mkdir -p "$TEST_ROOT/rw" "$TEST_ROOT/ro" "$TEST_ROOT/logs"
bin/container --debug system start \
--app-root "$TEST_ROOT/app" \
--install-root "$PWD" \
--log-root "$TEST_ROOT/logs" \
--enable-kernel-install \
--timeout 90
bin/container machine create --no-boot \
--name test-machine \
--home-mount=none \
--mount "$TEST_ROOT/rw:/audit-rw:rw" \
--mount "$TEST_ROOT/ro:/audit-ro:ro" \
ghcr.io/linuxcontainers/alpine:3.20
bin/container machine inspect test-machine | jq '.[0].mounts'
bin/container machine run --root -n test-machine -- touch /audit-rw/from-guest
test -f "$TEST_ROOT/rw/from-guest"
# This command should fail with "Read-only file system".
bin/container machine run --root -n test-machine -- touch /audit-ro/blocked
bin/container machine stop test-machine
bin/container machine rm test-machine
bin/container system stopI also added integration coverage for the create and inspect path plus the actual guest read-write and read-only behavior. If you still get an empty mount list with this setup, please share the output from |
Type of Change
Motivation and Context
Closes #1805.
container machinecurrently mounts only the user's home directory, configurable through--home-mount. There is no way to bind-mount additional arbitrary host directories into a machine, which the issue requests for parity with the container--volumeworkflow.This change adds a repeatable
--mount host:guest[:ro|rw]option tocontainer machine create:Summary of changes:
MachineConfiggains a self-containedMounttype (source,destination,readOnly) and amountsfield. Specifications are parsed and validated inwith(_:mounts:): the host path must be an existing directory, the guest path must be absolute, the mode must beroorrw(defaultrw), and duplicate destinations are rejected. Paths are resolved to absolute form at parse time.ConfigSnapshotDecoderpath because the system-wide[machine]TOML section cannot represent arrays of structs. Mounts are a per-machine value carried inboot-config.jsononly.MachinesService.toContainerConfigappends each configured mount as a virtiofs share at boot, alongside the existing home mount.container machine inspectsurfaces the configured mounts.Scope is limited to create time for this revision. Mounts are fixed for the lifetime of a machine. Adding or removing mounts on an existing machine through
container machine setis deferred because the currentkey=valuelast-wins semantics do not fit a repeatable list.Testing
Tested on Apple M5, macOS 26.5, Swift 6.3.3, using a debug build with all CLI and service components built from the same revision.
make container: passed and packaged the CLI and service plugins.make test: warnings-as-errors build passed, followed by all 765 non-integration tests.swift test --filter MachineConfigTests: all 22 tests passed.TestCLIMachineCommand/testCreateWithMounts: passed. It verifies that repeated read-write and read-only mount options survive create, persistence, and inspect.TestCLIMachineRuntimeSerial/testUserMountsReadWriteAndReadOnly: passed. It boots the machine, writes from the guest through the read-write mount, verifies the file on the host, and confirms that the read-only mount rejects writes.The same read-write propagation and read-only enforcement were also verified manually against an isolated application root.